<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				课程表
			</block>
		</cu-custom>
		<a-scroll :request="get" ref="aScroll" :parm="{pageSize:30}">
			<template #item="{row,index}">
				<wyb-table :defaultColWidth="ColWidth" :width="fullWidth" :minHeight="minHeight" :fontSize="fontSize" :height="fullHeight"
				 ref="table" :headers="headers" :contents="row" :url-col="urlCol" :firstLineFixed="true" />
			</template>
		</a-scroll>
	</view>
</template>

<script>
	import {
		getMonthWeek
	} from "@/a/utils/api.js";
	export default {
		//上拉触底
		onReachBottom() {
			this.$refs.aScroll.lower();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.aScroll.get(true).then(res => {
				uni.stopPullDownRefresh();
			});
		},
		data() {
			return {
				ColWidth: document.documentElement.clientWidth / 5,
				minHeight: [15, 30],
				fontSize: [14, 13],
				headers: [{
					label: '课时',
					key: 'classHour'
				}, {
					label: '周一',
					key: 'monday'
				}, {
					label: '周二',
					key: 'tuesday'
				}, {
					label: '周三',
					key: 'wednesday'
				}, {
					label: '周四',
					key: 'thursday'
				}, {
					label: '周五',
					key: 'friday'
				}, {
					label: '周六',
					key: 'saturday'
				}, {
					label: '周日',
					key: 'sunday'
				}],
				contents: [{
					classHour: {
						"id": 1,
						"classHourName": "第一节",
						"classHourTime": "08:00-08:45",
						"creator": "陆胡江",
						"createTime": "2020-09-10T21:16:29.000+00:00"
					},
					monday: {
						"courseId": 1,
						"subName": "机械管理",
						"subId": 1,
						"teacherId": 4,
						"teacherName": "陆胡江",
						"isDoubleWeek": "0"
					},
					tuesday: null,
					wednesday: null,
					thursday: null,
					friday: null,
					saturday: {
						"courseId": 6,
						"subName": "园林设计",
						"subId": 2,
						"teacherId": 10,
						"teacherName": "周总",
						"isDoubleWeek": "true"
					},
					sunday: null
				}],
				urlCol: [{
					type: 'route',
					key: 'url'
				}, {
					type: 'http',
					key: 'link'
				}],
				fullWidth: document.documentElement.clientWidth + "px",
				fullHeight: (document.documentElement.clientHeight - 90) + "px",
			}
		},
		created() {
			window.addEventListener('resize', this.handleResize)
		},
		beforeDestroy: function() {
			window.removeEventListener('resize', this.handleResize)
		},
		methods: {
			handleResize(event) {
				this.fullWidth = document.documentElement.clientWidth + "px"
				this.fullHeight = (document.documentElement.clientHeight - 90) + "px"
				this.ColWidth = document.documentElement.clientWidth / 5
			},
			get(parm = {}) {
				return this.$http.get('/api/v1/course/selectCourses', {
					...parm,
					classId: this.$store.state.userInfo.classId,
				}).then(res => {
					return {
						total: 0,
						data: [(res || [])]
					}
				});
			}
		}
	}
</script>
